<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<title>class Data - RDoc Documentation</title>


<script src="./js/navigation.js" defer></script>
<script src="./js/search.js" defer></script>
<script src="./js/search_index.js" defer></script>
<script src="./js/searcher.js" defer></script>
<script src="./js/darkfish.js" defer></script>

<script src="./js/jquery-3.2.0.min.js"></script>

<script src="./js/vue.min.js"></script>
<script src="./js/js.cookie.min.js"></script>

<link href="./css/fonts.css" rel="stylesheet">
<link id='rdoccss' href="./css/rdoc.css" rel="stylesheet">
<link href="./css/carbon17.css" rel="stylesheet">

<script type="text/javascript">
  var rdoc_rel_prefix = "./";
  var index_rel_prefix = "./";
  var darkModeCsseHref = "./css/rdoc-dm.css"
  var defaultModeCssHref = "./css/rdoc.css"
  // var cssDarkmode = Cookies.get('darkmode');
  
  if( Cookies.get("darkmode") == "true") {
	$('#rdoccss').attr("href", darkModeCsseHref);
}

//  https://cssdeck.com/blog/simple-jquery-stylesheet-switcher/

document.write('<style type="text/css">body{display:none}</style>');

</script>


</head>
<body id="top" role="document" class="class">
  <!-- this is class.html -->

  <div id='actionbar' >
    <div class='wrapper mdiv'>
      <ul class='grids g0'></ul>
    </div> 
    <!-- VERSION HEADER for 3.3.0-preview2 NOT FOUND -->
  </div> <!-- end action bar -->

  <div class='wrapper hdiv'>

    


    <nav id='vapp' role="navigation">
    <div id="project-navigation">
      <div id="home-section" role="region" title="Quick navigation" class="nav-section">
  <h2><a href="./index.html" rel="home">Home</a></h2>

  <div id="table-of-contents-navigation"  >
    <a href="./table_of_contents.html#pages">Pages</a>
    <a href="./table_of_contents.html#classes">Classes</a>
    <a href="./table_of_contents.html#methods">Methods</a>
  </div>
</div>

      <div id="search-section" role="search" class="project-section initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <div id="search-field-wrapper">
      <input id="search-field" role="combobox" aria-label="Search"
             aria-autocomplete="list" aria-controls="search-results"
             type="text" name="search" placeholder="Search" spellcheck="false"
             title="Type to search, Up and Down to navigate, Enter to load">
    </div>

    <ul id="search-results" aria-label="Search Results"
        aria-busy="false" aria-expanded="false"
        aria-atomic="false" class="initially-hidden"></ul>
  </form>
</div>

    </div>


    

    <button id='toggleThing' @click="toggleNav()" >Show/hide navigation</button>
    <div :class="isOpen ? 'block' : 'hidden' " id='toggleMe'>
      <div id="class-metadata">
        
        
<div id="parent-class-section" class="nav-section">
  <h3>Parent</h3>

  <p class="link"><a href="Object.html">Object</a>
</div>

        
        
        
<!-- Method Quickref -->
<div id="method-list-section" class="nav-section">
  <h3>Methods</h3>

  <ul class="link-list" role="directory">
    <li ><a href="#method-c-define">::define</a>
    <li ><a href="#method-c-members">::members</a>
    <li ><a href="#method-c-new">::new</a>
    <li ><a href="#method-i-3D-3D">#==</a>
    <li ><a href="#method-i-deconstruct">#deconstruct</a>
    <li ><a href="#method-i-deconstruct_keys">#deconstruct_keys</a>
    <li ><a href="#method-i-eql-3F">#eql?</a>
    <li ><a href="#method-i-hash">#hash</a>
    <li ><a href="#method-i-inspect">#inspect</a>
    <li ><a href="#method-i-members">#members</a>
    <li ><a href="#method-i-to_h">#to_h</a>
    <li ><a href="#method-i-to_s">#to_s</a>
    <li ><a href="#method-i-with">#with</a>
  </ul>
</div>

      </div>
     </div>
    </nav>


    <div id='extraz'><div class='adzbox-index'  >
      
     </div>         
    </div>

    <main role="main" aria-labelledby="class-Data">
    <h1 id="class-Data" class="class">
      class Data
    </h1>

    <section class="description">
    
<p>Class Data provides a convenient way to define simple classes for value-alike objects.</p>

<p>The simplest example of usage:</p>

<pre class="ruby"><span class="ruby-constant">Measure</span> = <span class="ruby-constant">Data</span>.<span class="ruby-identifier">define</span>(<span class="ruby-value">:amount</span>, <span class="ruby-value">:unit</span>)

<span class="ruby-comment"># Positional arguments constructor is provided</span>
<span class="ruby-identifier">distance</span> = <span class="ruby-constant">Measure</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">100</span>, <span class="ruby-string">&#39;km&#39;</span>)
<span class="ruby-comment">#=&gt; #&lt;data Measure amount=100, unit=&quot;km&quot;&gt;</span>

<span class="ruby-comment"># Keyword arguments constructor is provided</span>
<span class="ruby-identifier">weight</span> = <span class="ruby-constant">Measure</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">amount:</span> <span class="ruby-value">50</span>, <span class="ruby-value">unit:</span> <span class="ruby-string">&#39;kg&#39;</span>)
<span class="ruby-comment">#=&gt; #&lt;data Measure amount=50, unit=&quot;kg&quot;&gt;</span>

<span class="ruby-comment"># Alternative form to construct an object:</span>
<span class="ruby-identifier">speed</span> = <span class="ruby-constant">Measure</span>[<span class="ruby-value">10</span>, <span class="ruby-string">&#39;mPh&#39;</span>]
<span class="ruby-comment">#=&gt; #&lt;data Measure amount=10, unit=&quot;mPh&quot;&gt;</span>

<span class="ruby-comment"># Works with keyword arguments, too:</span>
<span class="ruby-identifier">area</span> = <span class="ruby-constant">Measure</span>[<span class="ruby-value">amount:</span> <span class="ruby-value">1.5</span>, <span class="ruby-value">unit:</span> <span class="ruby-string">&#39;m^2&#39;</span>]
<span class="ruby-comment">#=&gt; #&lt;data Measure amount=1.5, unit=&quot;m^2&quot;&gt;</span>

<span class="ruby-comment"># Argument accessors are provided:</span>
<span class="ruby-identifier">distance</span>.<span class="ruby-identifier">amount</span> <span class="ruby-comment">#=&gt; 100</span>
<span class="ruby-identifier">distance</span>.<span class="ruby-identifier">unit</span> <span class="ruby-comment">#=&gt; &quot;km&quot;</span>
</pre>

<p>Constructed object also has a reasonable definitions of <a href="Data.html#method-i-3D-3D"><code>==</code></a> operator, <a href="Data.html#method-i-to_h"><code>to_h</code></a> hash conversion, and <a href="Data.html#method-i-deconstruct"><code>deconstruct</code></a> / <a href="Data.html#method-i-deconstruct_keys"><code>deconstruct_keys</code></a> to be used in pattern matching.</p>

<p><a href="Data.html#method-c-define"><code>::define</code></a> method accepts an optional block and evaluates it in the context of the newly defined class. That allows to define additional methods:</p>

<pre class="ruby"><span class="ruby-constant">Measure</span> = <span class="ruby-constant">Data</span>.<span class="ruby-identifier">define</span>(<span class="ruby-value">:amount</span>, <span class="ruby-value">:unit</span>) <span class="ruby-keyword">do</span>
  <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">&lt;=&gt;</span>(<span class="ruby-identifier">other</span>)
    <span class="ruby-keyword">return</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">other</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-keyword">self</span>.<span class="ruby-identifier">class</span>) <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">other</span>.<span class="ruby-identifier">unit</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">unit</span>
    <span class="ruby-identifier">amount</span> <span class="ruby-operator">&lt;=&gt;</span> <span class="ruby-identifier">other</span>.<span class="ruby-identifier">amount</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">include</span> <span class="ruby-constant">Comparable</span>
<span class="ruby-keyword">end</span>

<span class="ruby-constant">Measure</span>[<span class="ruby-value">3</span>, <span class="ruby-string">&#39;m&#39;</span>] <span class="ruby-operator">&lt;</span> <span class="ruby-constant">Measure</span>[<span class="ruby-value">5</span>, <span class="ruby-string">&#39;m&#39;</span>] <span class="ruby-comment">#=&gt; true</span>
<span class="ruby-constant">Measure</span>[<span class="ruby-value">3</span>, <span class="ruby-string">&#39;m&#39;</span>] <span class="ruby-operator">&lt;</span> <span class="ruby-constant">Measure</span>[<span class="ruby-value">5</span>, <span class="ruby-string">&#39;kg&#39;</span>]
<span class="ruby-comment"># comparison of Measure with Measure failed (ArgumentError)</span>
</pre>

<p><a href="Data.html"><code>Data</code></a> provides no member writers, or enumerators: it is meant to be a storage for immutable atomic values. But note that if some of data members is of a mutable class, <a href="Data.html"><code>Data</code></a> does no additional immutability enforcement:</p>

<pre class="ruby"><span class="ruby-constant">Event</span> = <span class="ruby-constant">Data</span>.<span class="ruby-identifier">define</span>(<span class="ruby-value">:time</span>, <span class="ruby-value">:weekdays</span>)
<span class="ruby-identifier">event</span> = <span class="ruby-constant">Event</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;18:00&#39;</span>, <span class="ruby-node">%w[Tue Wed Fri]</span>)
<span class="ruby-comment">#=&gt; #&lt;data Event time=&quot;18:00&quot;, weekdays=[&quot;Tue&quot;, &quot;Wed&quot;, &quot;Fri&quot;]&gt;</span>

<span class="ruby-comment"># There is no #time= or #weekdays= accessors, but changes are</span>
<span class="ruby-comment"># still possible:</span>
<span class="ruby-identifier">event</span>.<span class="ruby-identifier">weekdays</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-string">&#39;Sat&#39;</span>
<span class="ruby-identifier">event</span>
<span class="ruby-comment">#=&gt; #&lt;data Event time=&quot;18:00&quot;, weekdays=[&quot;Tue&quot;, &quot;Wed&quot;, &quot;Fri&quot;, &quot;Sat&quot;]&gt;</span>
</pre>

<p>See also <a href="Struct.html"><code>Struct</code></a>, which is a similar concept, but has more container-alike API, allowing to change contents of the object and enumerate it.</p>

    </section>

      <section id="5Buntitled-5D" class="documentation-section">





                <section id="public-class-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Class Methods</h3>
                </header>

                  <div id="method-c-define" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          define(*symbols) &rarr; class
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Defines a new Data class.</p>

<pre class="ruby"><span class="ruby-identifier">measure</span> = <span class="ruby-constant">Data</span>.<span class="ruby-identifier">define</span>(<span class="ruby-value">:amount</span>, <span class="ruby-value">:unit</span>)
<span class="ruby-comment">#=&gt; #&lt;Class:0x00007f70c6868498&gt;</span>
<span class="ruby-identifier">measure</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">1</span>, <span class="ruby-string">&#39;km&#39;</span>)
<span class="ruby-comment">#=&gt; #&lt;data amount=1, unit=&quot;km&quot;&gt;</span>

<span class="ruby-comment"># It you store the new class in the constant, it will</span>
<span class="ruby-comment"># affect #inspect and will be more natural to use:</span>
<span class="ruby-constant">Measure</span> = <span class="ruby-constant">Data</span>.<span class="ruby-identifier">define</span>(<span class="ruby-value">:amount</span>, <span class="ruby-value">:unit</span>)
<span class="ruby-comment">#=&gt; Measure</span>
<span class="ruby-constant">Measure</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">1</span>, <span class="ruby-string">&#39;km&#39;</span>)
<span class="ruby-comment">#=&gt; #&lt;data Measure amount=1, unit=&quot;km&quot;&gt;</span>
</pre>

<p>Note that member-less Data is acceptable and might be a useful technique for defining several homogenous data classes, like</p>

<pre class="ruby"><span class="ruby-keyword">class</span> <span class="ruby-constant">HTTPFetcher</span>
  <span class="ruby-constant">Response</span> = <span class="ruby-constant">Data</span>.<span class="ruby-identifier">define</span>(<span class="ruby-value">:body</span>)
  <span class="ruby-constant">NotFound</span> = <span class="ruby-constant">Data</span>.<span class="ruby-identifier">define</span>
  <span class="ruby-comment"># ... implementation</span>
<span class="ruby-keyword">end</span>
</pre>

<p>Now, different kinds of responses from <code>HTTPFetcher</code> would have consistent representation:</p>

<pre class="ruby"><span class="ruby-comment">#&lt;data HTTPFetcher::Response body=&quot;&lt;html...&quot;&gt;</span>
<span class="ruby-comment">#&lt;data HTTPFetcher::NotFound&gt;</span>
</pre>

<p>And are convenient to use in pattern matching:</p>

<pre class="ruby"><span class="ruby-keyword">case</span> <span class="ruby-identifier">fetcher</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">url</span>)
<span class="ruby-keyword">in</span> <span class="ruby-constant">HTTPFetcher</span><span class="ruby-operator">::</span><span class="ruby-constant">Response</span>(<span class="ruby-identifier">body</span>)
  <span class="ruby-comment"># process body variable</span>
<span class="ruby-keyword">in</span> <span class="ruby-constant">HTTPFetcher</span><span class="ruby-operator">::</span><span class="ruby-constant">NotFound</span>
  <span class="ruby-comment"># handle not found case</span>
<span class="ruby-keyword">end</span>
</pre>

                              <div class="method-source-code" id="define-source">
            <pre>static VALUE
rb_data_s_def(int argc, VALUE *argv, VALUE klass)
{
    VALUE rest;
    long i;
    VALUE data_class;

    rest = rb_ident_hash_new();
    RBASIC_CLEAR_CLASS(rest);
    for (i=0; i&lt;argc; i++) {
        VALUE mem = rb_to_symbol(argv[i]);
        if (rb_is_attrset_sym(mem)) {
            rb_raise(rb_eArgError, &quot;invalid data member: %&quot;PRIsVALUE, mem);
        }
        if (RTEST(rb_hash_has_key(rest, mem))) {
            rb_raise(rb_eArgError, &quot;duplicate member: %&quot;PRIsVALUE, mem);
        }
        rb_hash_aset(rest, mem, Qtrue);
    }
    rest = rb_hash_keys(rest);
    RBASIC_CLEAR_CLASS(rest);
    OBJ_FREEZE_RAW(rest);
    data_class = anonymous_struct(klass);
    setup_data(data_class, rest);
    if (rb_block_given_p()) {
        rb_mod_module_eval(0, 0, data_class);
    }

    return data_class;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-members" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          DataClass::members &rarr; array_of_symbols
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns an array of member names of the data class:</p>

<pre class="ruby"><span class="ruby-constant">Measure</span> = <span class="ruby-constant">Data</span>.<span class="ruby-identifier">define</span>(<span class="ruby-value">:amount</span>, <span class="ruby-value">:unit</span>)
<span class="ruby-constant">Measure</span>.<span class="ruby-identifier">members</span> <span class="ruby-comment"># =&gt; [:amount, :unit]</span>
</pre>

                              <div class="method-source-code" id="members-source">
            <pre>#define rb_data_s_members_m rb_struct_s_members_m</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-new" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          new(*args) &rarr; instance
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          new(**kwargs) &rarr; instance
                              </span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          ::[](*args) &rarr; instance
                              </span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          ::[](**kwargs) &rarr; instance
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Constructors for classes defined with <a href="Data.html#method-c-define"><code>::define</code></a> accept both positional and keyword arguments.</p>

<pre class="ruby"><span class="ruby-constant">Measure</span> = <span class="ruby-constant">Data</span>.<span class="ruby-identifier">define</span>(<span class="ruby-value">:amount</span>, <span class="ruby-value">:unit</span>)

<span class="ruby-constant">Measure</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">1</span>, <span class="ruby-string">&#39;km&#39;</span>)
<span class="ruby-comment">#=&gt; #&lt;data Measure amount=1, unit=&quot;km&quot;&gt;</span>
<span class="ruby-constant">Measure</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">amount:</span> <span class="ruby-value">1</span>, <span class="ruby-value">unit:</span> <span class="ruby-string">&#39;km&#39;</span>)
<span class="ruby-comment">#=&gt; #&lt;data Measure amount=1, unit=&quot;km&quot;&gt;</span>

<span class="ruby-comment"># Alternative shorter initialization with []</span>
<span class="ruby-constant">Measure</span>[<span class="ruby-value">1</span>, <span class="ruby-string">&#39;km&#39;</span>]
<span class="ruby-comment">#=&gt; #&lt;data Measure amount=1, unit=&quot;km&quot;&gt;</span>
<span class="ruby-constant">Measure</span>[<span class="ruby-value">amount:</span> <span class="ruby-value">1</span>, <span class="ruby-value">unit:</span> <span class="ruby-string">&#39;km&#39;</span>]
<span class="ruby-comment">#=&gt; #&lt;data Measure amount=1, unit=&quot;km&quot;&gt;</span>
</pre>

<p>All arguments are mandatory (unlike <a href="Struct.html"><code>Struct</code></a>), and converted to keyword arguments:</p>

<pre class="ruby"><span class="ruby-constant">Measure</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">amount:</span> <span class="ruby-value">1</span>)
<span class="ruby-comment"># in `initialize&#39;: missing keyword: :unit (ArgumentError)</span>

<span class="ruby-constant">Measure</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">1</span>)
<span class="ruby-comment"># in `initialize&#39;: missing keyword: :unit (ArgumentError)</span>
</pre>

<p>Note that <code>Measure#initialize</code> always receives keyword arguments, and that mandatory arguments are checked in <code>initialize</code>, not in <code>new</code>. This can be important for redefining initialize in order to convert arguments or provide defaults:</p>

<pre class="ruby"><span class="ruby-constant">Measure</span> = <span class="ruby-constant">Data</span>.<span class="ruby-identifier">define</span>(<span class="ruby-value">:amount</span>, <span class="ruby-value">:unit</span>) <span class="ruby-keyword">do</span>
  <span class="ruby-constant">NONE</span> = <span class="ruby-constant">Data</span>.<span class="ruby-identifier">define</span>

  <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">initialize</span>(<span class="ruby-value">amount:</span>, <span class="ruby-value">unit:</span> <span class="ruby-constant">NONE</span>.<span class="ruby-identifier">new</span>)
    <span class="ruby-keyword">super</span>(<span class="ruby-value">amount:</span> <span class="ruby-constant">Float</span>(<span class="ruby-identifier">amount</span>), <span class="ruby-value">unit:</span>)
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span>

<span class="ruby-constant">Measure</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;10&#39;</span>, <span class="ruby-string">&#39;km&#39;</span>) <span class="ruby-comment"># =&gt; #&lt;data Measure amount=10.0, unit=&quot;km&quot;&gt;</span>
<span class="ruby-constant">Measure</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">10_000</span>)     <span class="ruby-comment"># =&gt; #&lt;data Measure amount=10000.0, unit=#&lt;data NONE&gt;&gt;</span>
</pre>

                              <div class="method-source-code" id="new-source">
            <pre>static VALUE
rb_data_initialize_m(int argc, const VALUE *argv, VALUE self)
{
    VALUE klass = rb_obj_class(self);
    rb_struct_modify(self);
    VALUE members = struct_ivar_get(klass, id_members);
    size_t num_members = RARRAY_LEN(members);

    if (argc == 0) {
        if (num_members &gt; 0) {
            rb_exc_raise(rb_keyword_error_new(&quot;missing&quot;, members));
        }
        return Qnil;
    }
    if (argc &gt; 1 || !RB_TYPE_P(argv[0], T_HASH)) {
        rb_error_arity(argc, 0, 0);
    }

    if (RHASH_SIZE(argv[0]) &lt; num_members) {
        VALUE missing = rb_ary_diff(members, rb_hash_keys(argv[0]));
        rb_exc_raise(rb_keyword_error_new(&quot;missing&quot;, missing));
    }

    struct struct_hash_set_arg arg;
    rb_mem_clear((VALUE *)RSTRUCT_CONST_PTR(self), num_members);
    arg.self = self;
    arg.unknown_keywords = Qnil;
    rb_hash_foreach(argv[0], struct_hash_set_i, (VALUE)&amp;arg);
    // Freeze early before potentially raising, so that we don&#39;t leave an
    // unfrozen copy on the heap, which could get exposed via ObjectSpace.
    OBJ_FREEZE_RAW(self);
    if (arg.unknown_keywords != Qnil) {
        rb_exc_raise(rb_keyword_error_new(&quot;unknown&quot;, arg.unknown_keywords));
    }
    return Qnil;
}</pre>
                              </div>
                            </div>


                          </div>

                          </section>

                <section id="public-instance-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Instance Methods</h3>
                </header>

                  <div id="method-i-3D-3D" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          self == other &rarr; true or false
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns  <code>true</code> if <code>other</code> is the same class as <code>self</code>, and all members are equal.</p>

<p>Examples:</p>

<pre class="ruby"><span class="ruby-constant">Measure</span> = <span class="ruby-constant">Data</span>.<span class="ruby-identifier">define</span>(<span class="ruby-value">:amount</span>, <span class="ruby-value">:unit</span>)

<span class="ruby-constant">Measure</span>[<span class="ruby-value">1</span>, <span class="ruby-string">&#39;km&#39;</span>] <span class="ruby-operator">==</span> <span class="ruby-constant">Measure</span>[<span class="ruby-value">1</span>, <span class="ruby-string">&#39;km&#39;</span>] <span class="ruby-comment">#=&gt; true</span>
<span class="ruby-constant">Measure</span>[<span class="ruby-value">1</span>, <span class="ruby-string">&#39;km&#39;</span>] <span class="ruby-operator">==</span> <span class="ruby-constant">Measure</span>[<span class="ruby-value">2</span>, <span class="ruby-string">&#39;km&#39;</span>] <span class="ruby-comment">#=&gt; false</span>
<span class="ruby-constant">Measure</span>[<span class="ruby-value">1</span>, <span class="ruby-string">&#39;km&#39;</span>] <span class="ruby-operator">==</span> <span class="ruby-constant">Measure</span>[<span class="ruby-value">1</span>, <span class="ruby-string">&#39;m&#39;</span>]  <span class="ruby-comment">#=&gt; false</span>

<span class="ruby-constant">Measurement</span> = <span class="ruby-constant">Data</span>.<span class="ruby-identifier">define</span>(<span class="ruby-value">:amount</span>, <span class="ruby-value">:unit</span>)
<span class="ruby-comment"># Even though Measurement and Measure have the same &quot;shape&quot;</span>
<span class="ruby-comment"># their instances are never equal</span>
<span class="ruby-constant">Measure</span>[<span class="ruby-value">1</span>, <span class="ruby-string">&#39;km&#39;</span>] <span class="ruby-operator">==</span> <span class="ruby-constant">Measurement</span>[<span class="ruby-value">1</span>, <span class="ruby-string">&#39;km&#39;</span>] <span class="ruby-comment">#=&gt; false</span>
</pre>

                              <div class="method-source-code" id="3D-3D-source">
            <pre>#define rb_data_equal rb_struct_equal</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-deconstruct" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          deconstruct     &rarr; array
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the values in <code>self</code> as an array, to use in pattern matching:</p>

<pre class="ruby"><span class="ruby-constant">Measure</span> = <span class="ruby-constant">Data</span>.<span class="ruby-identifier">define</span>(<span class="ruby-value">:amount</span>, <span class="ruby-value">:unit</span>)

<span class="ruby-identifier">distance</span> = <span class="ruby-constant">Measure</span>[<span class="ruby-value">10</span>, <span class="ruby-string">&#39;km&#39;</span>]
<span class="ruby-identifier">distance</span>.<span class="ruby-identifier">deconstruct</span> <span class="ruby-comment">#=&gt; [10, &quot;km&quot;]</span>

<span class="ruby-comment"># usage</span>
<span class="ruby-keyword">case</span> <span class="ruby-identifier">distance</span>
<span class="ruby-keyword">in</span> <span class="ruby-identifier">n</span>, <span class="ruby-string">&#39;km&#39;</span> <span class="ruby-comment"># calls #deconstruct underneath</span>
  <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;It is #{n} kilometers away&quot;</span>
<span class="ruby-keyword">else</span>
  <span class="ruby-identifier">puts</span> <span class="ruby-string">&quot;Don&#39;t know how to handle it&quot;</span>
<span class="ruby-keyword">end</span>
<span class="ruby-comment"># prints &quot;It is 10 kilometers away&quot;</span>
</pre>

<p>Or, with checking the class, too:</p>

<pre class="ruby"><span class="ruby-keyword">case</span> <span class="ruby-identifier">distance</span>
<span class="ruby-keyword">in</span> <span class="ruby-constant">Measure</span>(<span class="ruby-identifier">n</span>, <span class="ruby-string">&#39;km&#39;</span>)
  <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;It is #{n} kilometers away&quot;</span>
<span class="ruby-comment"># ...</span>
<span class="ruby-keyword">end</span>
</pre>

                              <div class="method-source-code" id="deconstruct-source">
            <pre>#define rb_data_deconstruct rb_struct_to_a</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-deconstruct_keys" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          deconstruct_keys(array_of_names_or_nil) &rarr; hash
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns a hash of the name/value pairs, to use in pattern matching.</p>

<pre class="ruby"><span class="ruby-constant">Measure</span> = <span class="ruby-constant">Data</span>.<span class="ruby-identifier">define</span>(<span class="ruby-value">:amount</span>, <span class="ruby-value">:unit</span>)

<span class="ruby-identifier">distance</span> = <span class="ruby-constant">Measure</span>[<span class="ruby-value">10</span>, <span class="ruby-string">&#39;km&#39;</span>]
<span class="ruby-identifier">distance</span>.<span class="ruby-identifier">deconstruct_keys</span>(<span class="ruby-keyword">nil</span>) <span class="ruby-comment">#=&gt; {:amount=&gt;10, :unit=&gt;&quot;km&quot;}</span>
<span class="ruby-identifier">distance</span>.<span class="ruby-identifier">deconstruct_keys</span>([<span class="ruby-value">:amount</span>]) <span class="ruby-comment">#=&gt; {:amount=&gt;10}</span>

<span class="ruby-comment"># usage</span>
<span class="ruby-keyword">case</span> <span class="ruby-identifier">distance</span>
<span class="ruby-keyword">in</span> <span class="ruby-value">amount:</span>, <span class="ruby-value">unit:</span> <span class="ruby-string">&#39;km&#39;</span> <span class="ruby-comment"># calls #deconstruct_keys underneath</span>
  <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;It is #{amount} kilometers away&quot;</span>
<span class="ruby-keyword">else</span>
  <span class="ruby-identifier">puts</span> <span class="ruby-string">&quot;Don&#39;t know how to handle it&quot;</span>
<span class="ruby-keyword">end</span>
<span class="ruby-comment"># prints &quot;It is 10 kilometers away&quot;</span>
</pre>

<p>Or, with checking the class, too:</p>

<pre class="ruby"><span class="ruby-keyword">case</span> <span class="ruby-identifier">distance</span>
<span class="ruby-keyword">in</span> <span class="ruby-constant">Measure</span>(<span class="ruby-value">amount:</span>, <span class="ruby-value">unit:</span> <span class="ruby-string">&#39;km&#39;</span>)
  <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;It is #{amount} kilometers away&quot;</span>
<span class="ruby-comment"># ...</span>
<span class="ruby-keyword">end</span>
</pre>

                              <div class="method-source-code" id="deconstruct_keys-source">
            <pre>#define rb_data_deconstruct_keys rb_struct_deconstruct_keys</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-eql-3F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          eql?(other) &rarr; true or false
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Equality check that is used when two items of data are keys of a <a href="Hash.html"><code>Hash</code></a>.</p>

<p>The subtle difference with <a href="Data.html#method-i-3D-3D"><code>==</code></a> is that members are also compared with their <a href="Data.html#method-i-eql-3F"><code>eql?</code></a> method, which might be important in some cases:</p>

<pre class="ruby"><span class="ruby-constant">Measure</span> = <span class="ruby-constant">Data</span>.<span class="ruby-identifier">define</span>(<span class="ruby-value">:amount</span>, <span class="ruby-value">:unit</span>)

<span class="ruby-constant">Measure</span>[<span class="ruby-value">1</span>, <span class="ruby-string">&#39;km&#39;</span>] <span class="ruby-operator">==</span> <span class="ruby-constant">Measure</span>[<span class="ruby-value">1.0</span>, <span class="ruby-string">&#39;km&#39;</span>] <span class="ruby-comment">#=&gt; true, they are equal as values</span>
<span class="ruby-comment"># ...but...</span>
<span class="ruby-constant">Measure</span>[<span class="ruby-value">1</span>, <span class="ruby-string">&#39;km&#39;</span>].<span class="ruby-identifier">eql?</span> <span class="ruby-constant">Measure</span>[<span class="ruby-value">1.0</span>, <span class="ruby-string">&#39;km&#39;</span>] <span class="ruby-comment">#=&gt; false, they represent different hash keys</span>
</pre>

<p>See also <a href="Object.html#method-i-eql-3F"><code>Object#eql?</code></a> for further explanations of the method usage.</p>

                              <div class="method-source-code" id="eql-3F-source">
            <pre>#define rb_data_eql rb_struct_eql</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-hash" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          hash &rarr; integer
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Redefines <a href="Object.html#method-i-hash"><code>Object#hash</code></a> (used to distinguish objects as <a href="Hash.html"><code>Hash</code></a> keys) so that data objects of the same class with same content would have the same <code>hash</code> value, and represented the same <a href="Hash.html"><code>Hash</code></a> key.</p>

<pre class="ruby"><span class="ruby-constant">Measure</span> = <span class="ruby-constant">Data</span>.<span class="ruby-identifier">define</span>(<span class="ruby-value">:amount</span>, <span class="ruby-value">:unit</span>)

<span class="ruby-constant">Measure</span>[<span class="ruby-value">1</span>, <span class="ruby-string">&#39;km&#39;</span>].<span class="ruby-identifier">hash</span> <span class="ruby-operator">==</span> <span class="ruby-constant">Measure</span>[<span class="ruby-value">1</span>, <span class="ruby-string">&#39;km&#39;</span>].<span class="ruby-identifier">hash</span> <span class="ruby-comment">#=&gt; true</span>
<span class="ruby-constant">Measure</span>[<span class="ruby-value">1</span>, <span class="ruby-string">&#39;km&#39;</span>].<span class="ruby-identifier">hash</span> <span class="ruby-operator">==</span> <span class="ruby-constant">Measure</span>[<span class="ruby-value">10</span>, <span class="ruby-string">&#39;km&#39;</span>].<span class="ruby-identifier">hash</span> <span class="ruby-comment">#=&gt; false</span>
<span class="ruby-constant">Measure</span>[<span class="ruby-value">1</span>, <span class="ruby-string">&#39;km&#39;</span>].<span class="ruby-identifier">hash</span> <span class="ruby-operator">==</span> <span class="ruby-constant">Measure</span>[<span class="ruby-value">1</span>, <span class="ruby-string">&#39;m&#39;</span>].<span class="ruby-identifier">hash</span> <span class="ruby-comment">#=&gt; false</span>
<span class="ruby-constant">Measure</span>[<span class="ruby-value">1</span>, <span class="ruby-string">&#39;km&#39;</span>].<span class="ruby-identifier">hash</span> <span class="ruby-operator">==</span> <span class="ruby-constant">Measure</span>[<span class="ruby-value">1.0</span>, <span class="ruby-string">&#39;km&#39;</span>].<span class="ruby-identifier">hash</span> <span class="ruby-comment">#=&gt; false</span>

<span class="ruby-comment"># Structurally similar data class, but shouldn&#39;t be considered</span>
<span class="ruby-comment"># the same hash key</span>
<span class="ruby-constant">Measurement</span> = <span class="ruby-constant">Data</span>.<span class="ruby-identifier">define</span>(<span class="ruby-value">:amount</span>, <span class="ruby-value">:unit</span>)

<span class="ruby-constant">Measure</span>[<span class="ruby-value">1</span>, <span class="ruby-string">&#39;km&#39;</span>].<span class="ruby-identifier">hash</span> <span class="ruby-operator">==</span> <span class="ruby-constant">Measurement</span>[<span class="ruby-value">1</span>, <span class="ruby-string">&#39;km&#39;</span>].<span class="ruby-identifier">hash</span> <span class="ruby-comment">#=&gt; false</span>
</pre>

                              <div class="method-source-code" id="hash-source">
            <pre>#define rb_data_hash rb_struct_hash</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-inspect" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          inspect &rarr; string
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns a string representation of <code>self</code>:</p>

<pre class="ruby"><span class="ruby-constant">Measure</span> = <span class="ruby-constant">Data</span>.<span class="ruby-identifier">define</span>(<span class="ruby-value">:amount</span>, <span class="ruby-value">:unit</span>)

<span class="ruby-identifier">distance</span> = <span class="ruby-constant">Measure</span>[<span class="ruby-value">10</span>, <span class="ruby-string">&#39;km&#39;</span>]

<span class="ruby-identifier">p</span> <span class="ruby-identifier">distance</span>  <span class="ruby-comment"># uses #inspect underneath</span>
<span class="ruby-comment">#&lt;data Measure amount=10, unit=&quot;km&quot;&gt;</span>

<span class="ruby-identifier">puts</span> <span class="ruby-identifier">distance</span>  <span class="ruby-comment"># uses #to_s underneath, same representation</span>
<span class="ruby-comment">#&lt;data Measure amount=10, unit=&quot;km&quot;&gt;</span>
</pre>

                              <div class="method-source-code" id="inspect-source">
            <pre>static VALUE
rb_data_inspect(VALUE s)
{
    return rb_exec_recursive(inspect_struct, s, rb_str_new2(&quot;#&lt;data &quot;));
}</pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="Data.html#method-i-to_s">to_s</a>
                            </div>

                          </div>

                  <div id="method-i-members" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          members &rarr; array_of_symbols
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the member names from <code>self</code> as an array:</p>

<pre class="ruby"><span class="ruby-constant">Measure</span> = <span class="ruby-constant">Data</span>.<span class="ruby-identifier">define</span>(<span class="ruby-value">:amount</span>, <span class="ruby-value">:unit</span>)
<span class="ruby-identifier">distance</span> = <span class="ruby-constant">Measure</span>[<span class="ruby-value">10</span>, <span class="ruby-string">&#39;km&#39;</span>]

<span class="ruby-identifier">distance</span>.<span class="ruby-identifier">members</span> <span class="ruby-comment">#=&gt; [:amount, :unit]</span>
</pre>

                              <div class="method-source-code" id="members-source">
            <pre>#define rb_data_members_m rb_struct_members_m</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-to_h" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          to_h &rarr; hash
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          to_h {|name, value| ... } &rarr; hash
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Returns <a href="Hash.html"><code>Hash</code></a> representation of the data object.</p>

<pre class="ruby"><span class="ruby-constant">Measure</span> = <span class="ruby-constant">Data</span>.<span class="ruby-identifier">define</span>(<span class="ruby-value">:amount</span>, <span class="ruby-value">:unit</span>)
<span class="ruby-identifier">distance</span> = <span class="ruby-constant">Measure</span>[<span class="ruby-value">10</span>, <span class="ruby-string">&#39;km&#39;</span>]

<span class="ruby-identifier">distance</span>.<span class="ruby-identifier">to_h</span>
<span class="ruby-comment">#=&gt; {:amount=&gt;10, :unit=&gt;&quot;km&quot;}</span>
</pre>

<p>Like <a href="Enumerable.html#method-i-to_h"><code>Enumerable#to_h</code></a>, if the block is provided, it is expected to produce key-value pairs to construct a hash:</p>

<pre class="ruby"><span class="ruby-identifier">distance</span>.<span class="ruby-identifier">to_h</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">name</span>, <span class="ruby-identifier">val</span><span class="ruby-operator">|</span> [<span class="ruby-identifier">name</span>.<span class="ruby-identifier">to_s</span>, <span class="ruby-identifier">val</span>.<span class="ruby-identifier">to_s</span>] }
<span class="ruby-comment">#=&gt; {&quot;amount&quot;=&gt;&quot;10&quot;, &quot;unit&quot;=&gt;&quot;km&quot;}</span>
</pre>

<p>Note that there is a useful symmetry between <a href="Data.html#method-i-to_h"><code>to_h</code></a> and initialize:</p>

<pre class="ruby"><span class="ruby-identifier">distance2</span> = <span class="ruby-constant">Measure</span>.<span class="ruby-identifier">new</span>(<span class="ruby-operator">**</span><span class="ruby-identifier">distance</span>.<span class="ruby-identifier">to_h</span>)
<span class="ruby-comment">#=&gt; #&lt;data Measure amount=10, unit=&quot;km&quot;&gt;</span>
<span class="ruby-identifier">distance2</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">distance</span>
<span class="ruby-comment">#=&gt; true</span>
</pre>

                              <div class="method-source-code" id="to_h-source">
            <pre>#define rb_data_to_h rb_struct_to_h</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-to_s" class="method-detail method-alias">
                      <div class="method-heading">
                        <span class="method-callseq">
                          to_s &rarr; string
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Returns a string representation of <code>self</code>:</p>

<pre class="ruby"><span class="ruby-constant">Measure</span> = <span class="ruby-constant">Data</span>.<span class="ruby-identifier">define</span>(<span class="ruby-value">:amount</span>, <span class="ruby-value">:unit</span>)

<span class="ruby-identifier">distance</span> = <span class="ruby-constant">Measure</span>[<span class="ruby-value">10</span>, <span class="ruby-string">&#39;km&#39;</span>]

<span class="ruby-identifier">p</span> <span class="ruby-identifier">distance</span>  <span class="ruby-comment"># uses #inspect underneath</span>
<span class="ruby-comment">#&lt;data Measure amount=10, unit=&quot;km&quot;&gt;</span>

<span class="ruby-identifier">puts</span> <span class="ruby-identifier">distance</span>  <span class="ruby-comment"># uses #to_s underneath, same representation</span>
<span class="ruby-comment">#&lt;data Measure amount=10, unit=&quot;km&quot;&gt;</span>
</pre>

                            </div>


                            <div class="aliases">
                              Alias for: <a href="Data.html#method-i-inspect">inspect</a>
                            </div>
                          </div>

                  <div id="method-i-with" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          with(**kwargs) &rarr; instance
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns a shallow copy of <code>self</code> — the instance variables of <code>self</code> are copied, but not the objects they reference.</p>

<p>If the method is supplied any keyword arguments, the copy will be created with the respective field values updated to use the supplied keyword argument values. Note that it is an error to supply a keyword that the <a href="Data.html"><code>Data</code></a> class does not have as a member.</p>

<pre class="ruby"><span class="ruby-constant">Point</span> = <span class="ruby-constant">Data</span>.<span class="ruby-identifier">define</span>(<span class="ruby-value">:x</span>, <span class="ruby-value">:y</span>)

<span class="ruby-identifier">origin</span> = <span class="ruby-constant">Point</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">x:</span> <span class="ruby-value">0</span>, <span class="ruby-value">y:</span> <span class="ruby-value">0</span>)

<span class="ruby-identifier">up</span> = <span class="ruby-identifier">origin</span>.<span class="ruby-identifier">with</span>(<span class="ruby-value">x:</span> <span class="ruby-value">1</span>)
<span class="ruby-identifier">right</span> = <span class="ruby-identifier">origin</span>.<span class="ruby-identifier">with</span>(<span class="ruby-value">y:</span> <span class="ruby-value">1</span>)
<span class="ruby-identifier">up_and_right</span> = <span class="ruby-identifier">up</span>.<span class="ruby-identifier">with</span>(<span class="ruby-value">y:</span> <span class="ruby-value">1</span>)

<span class="ruby-identifier">p</span> <span class="ruby-identifier">origin</span>       <span class="ruby-comment"># #&lt;data Point x=0, y=0&gt;</span>
<span class="ruby-identifier">p</span> <span class="ruby-identifier">up</span>           <span class="ruby-comment"># #&lt;data Point x=1, y=0&gt;</span>
<span class="ruby-identifier">p</span> <span class="ruby-identifier">right</span>        <span class="ruby-comment"># #&lt;data Point x=0, y=1&gt;</span>
<span class="ruby-identifier">p</span> <span class="ruby-identifier">up_and_right</span> <span class="ruby-comment"># #&lt;data Point x=1, y=1&gt;</span>

<span class="ruby-identifier">out</span> = <span class="ruby-identifier">origin</span>.<span class="ruby-identifier">with</span>(<span class="ruby-value">z:</span> <span class="ruby-value">1</span>) <span class="ruby-comment"># ArgumentError: unknown keyword: :z</span>
<span class="ruby-identifier">some_point</span> = <span class="ruby-identifier">origin</span>.<span class="ruby-identifier">with</span>(<span class="ruby-value">1</span>, <span class="ruby-value">2</span>) <span class="ruby-comment"># ArgumentError: expected keyword arguments, got positional arguments</span>
</pre>

                              <div class="method-source-code" id="with-source">
            <pre>static VALUE
rb_data_with(int argc, const VALUE *argv, VALUE self)
{
    VALUE kwargs;
    rb_scan_args(argc, argv, &quot;0:&quot;, &amp;kwargs);
    if (NIL_P(kwargs)) {
        return self;
    }

    VALUE h = rb_struct_to_h(self);
    rb_hash_update_by(h, kwargs, 0);
    return rb_class_new_instance_kw(1, &amp;h, rb_obj_class(self), TRUE);
}</pre>
                              </div>
                            </div>


                          </div>

                          </section>

              </section>
              </main>



            </div>  <!--  class='wrapper hdiv' -->


<footer id="validator-badges" role="contentinfo">
<p><a href="https://validator.w3.org/check/referer">Validate</a></p>
<p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.4.0.</p>
<p>Based on <a href="https://github.com/ged/darkfish/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.</p>

  
    <p><p><a href="https://ruby-doc.org">Ruby-doc.org</a> is provided by <a href="https://jamesbritt.com">James Britt</a> and <a href="https://neurogami.com">Neurogami</a>.</p><p><a href="https://jamesbritt.bandcamp.com/">Maximum R+D</a>.  </p>
</p>
  
  </footer>

<script type="text/javascript">


  let ads  = $("#carbonads-container").children().detach();


  function swapMode() {
    var cookieName = 'darkmode';
    var cssDarkmode = Cookies.get(cookieName);
    console.log("***** swapMode! " + cssDarkmode + " *****");


    if (cssDarkmode == "true") {
      console.log("We have dark mode, set the css to light ...");
      $('#rdoccss').attr("href", defaultModeCssHref);
      $('#cssSelect').text("Dark mode");
      cssDarkmode = "false";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    } else {
      console.log("We not have dark mode, set the css to dark ...");
      $('#rdoccss').attr("href", darkModeCsseHref);
      $('#cssSelect').text("Light mode");
      cssDarkmode = "true";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    }

    console.log("  --------------- ");
  }


const vueCssApp = new Vue({
el: '#menubar',
data: {
isDark: false
},
methods: {
toggleClass: function(event){
this.isDark = !this.isDark;
}
}
})

const vueApp = new Vue({
el: '#vapp',
data: { 
isOpen: true
},

mounted() {
this.handleResize();
this.manage_mob_classes();
window.addEventListener('resize', this.handleResize)
//this.isOpen !=  (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},
destroyed() {
window.removeEventListener('resize', this.handleResize)
},
created() {
//manage_mob_classes();
},

methods : {
isMobile() {
  return (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},

  handleResize() {
    if (!this.isMobile()) {
      this.isOpen = window.innerWidth > 800;
    }
  },

  manage_mob_classes() {
    if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
      $("nav").addClass("mob_nav");
      $("main").addClass("mob_main");
      $("#extraz").addClass("mob_extraz");
      $("#carbonads-container").addClass("mob_carbonads-container");
      this.isOpen  = false;
    } else {
      $("nav").removeClass("mob_nav") 
        $("main").removeClass("mob_main");
      $("#extraz").removeClass("mob_extraz");
      $("#carbonads-container").removeClass("mob_carbonads-container");
      this.isOpen  = true;
    }
  },

  toggleNav() {
    this.isOpen =! this.isOpen ;
    // alert("Toggle nav!");
    console.log("toggleNav() click: " + this.isOpen );
  }
}
})

$("#carbonads-container").append(ads);


$(function() {

    var darkmode = Cookies.get("darkmode");
    console.log("Document ready: " + darkmode);

    if ( darkmode  == "true" ) {
      $('#cssSelect').text("Light mode");
    } else {
      $('#cssSelect').text("Dark mode");
     }

    $('body').css('display','block');
    });

</script>

    
  </body> 
</html>

